import Cookies from 'js-cookie' // js 操作cookie的工具类
import UUID from '@/utils/createUniqueString'
/**
 * 权限认证工具类
 */
// token的key
const TokenKey = 'ms-Token'

// 刷新token的key
const RefreshToken = 'ms-RefreshToken'

// 机器id的key
const DevicedId = 'ms-DeviceId'

export function getToken() {
  return Cookies.get(TokenKey)
}
export function setToken(token) {
  return Cookies.set(TokenKey, token)
}
export function removeToken() {
  return Cookies.remove(TokenKey)
}

export function removeRefreshToken() {
  return Cookies.remove(RefreshToken)
}
export function getRefreshToken() {
  return Cookies.get(RefreshToken)
}
export function setRefreshToken(refreshToken) {
  return Cookies.set(RefreshToken, refreshToken)
}

/**
 * 获取deviceId
 * @returns {*}
 */
export function getDeviceId() {
  let deviceId = Cookies.get(DevicedId)
  if (deviceId) {
    return deviceId
  } else {
    deviceId = UUID()
    setDeviceId(deviceId)
    return deviceId
  }
}
export function setDeviceId(deviceId) {
  return Cookies.set(DevicedId, deviceId)
}
export function removeDeviceId() {
  return Cookies.remove(DevicedId)
}

